import util from './utils'
import styles from './style'
import { config as sysconfig } from './config'
import Point from 'ol/geom/Point'
import Circle from 'ol/geom/Circle'
import Feature from 'ol/Feature'
import LineString from 'ol/geom/LineString'
import Polygon from 'ol/geom/Polygon'

const polygon = {
    // 绘制点,
    // layer图层对象，style样式，lonlats经纬度，attrs自定义属性
    drawPolygon: (layer, style, lonlats, type, attrs = {}, radius = 50000) => {
        if (!style) {
            style = {
                stroke: {
                    color: 'rgba(0, 255, 255, 1)',
                    width: 3
                },
                fill: {
                    color: 'rgba(0, 255, 255, .6)'
                }
            }
        }
        let feature = null
        if (type === 'point') {
            feature = new Feature(new Point(util.transform(lonlats)))
        } else if (type === 'line') {
            feature = new Feature({
                geometry: new LineString(util.transforms(lonlats))
            })
        } else if (type === 'polygon') {
            feature = new Feature(new Polygon([util.transforms(lonlats)]))
        } else if (type === 'circle') {
            feature = new Feature(new Circle(util.transform(lonlats), radius))
        }
        feature.set('geomName', type)
        feature.setStyle(styles.init(style)[0])
        for (let key in attrs) {
            feature.set(key, attrs[key])
        }
        layer.getSource().addFeature(feature)
        return feature
    }
    // // 绘制线条
    // drawLine: (layer, style, lonlats, type, attrs = {}) => {

    // }
}

export default polygon
